<?php

namespace lib\amqp;

use Swoole\Coroutine;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

use lib\pool\abstractPool;

class amqpPool extends abstractPool
{
    private $amqp_pool = null;
    private $db = null;
    
    public $dbConfig = array();
    public static $instance;
 
    public static function getInstance()
    {
        if (is_null(self::$instance)) {
            self::$instance = new amqpPool();
        }
        return self::$instance;
    }

    public function initConfig($config = array()) {
	    
        $this->dbConfig = $config;
        $this->init();
    }

    protected function createDb()
    {
        try{
            
            $connection = new AMQPStreamConnection($this->dbConfig["RABBITMQ_SERVER_IP"], $this->dbConfig["RABBITMQ_SERVER_PORT"], $this->dbConfig["RABBITMQ_SERVER_USER"], $this->dbConfig["RABBITMQ_SERVER_PASS"], $this->dbConfig["RABBITMQ_SERVER_VHOST"]);
            $channel = $connection->channel();
            return $channel;
        }catch(Exception $e){
            var_dump($e->getMessage());
            return false;
        }
    }
}
